{
LANG : PASCAL
PROB : wall
}

program WALL;
const
  fi = 'wall.in';
  fo = 'wall.out';
  max = 10001;
  maxc = 300000;
  oo = 1000000;
type
  integer = longint;
  point = record
            x, y : longint;
          end;
var
  p : array[1..max] of point;
  d : array[1..max] of longint;
  c : array[1..max+1] of longint;
  h, v : array[1..max] of longint;
  a : array[1..2*maxc] of integer;
  e : array[1..maxc, 1..2] of integer;
  n, l, m, size, res : longint;

procedure inp;
var
  i : integer;
begin
  read(l, n);
  for i := 1 to n do
    with p[i] do read(x, y);
end;

procedure swap1(i, j : integer);
var
  temp : point;
begin
  temp := p[i];
  p[i] := p[j];
  p[j] := temp;
end;

procedure sortx(l, r : longint);
var
  i, j, k : longint;
begin
  if l >= r then exit;
  i := l;
  j := r;
  k := p[l+random(r-l+1)].x;
  repeat
    while p[i].x < k do inc(i);
    while p[j].x > k do dec(j);
    if i <= j then
    begin
      swap1(i, j);
      inc(i); dec(j);
    end;
  until i > j;
  sortx(i, r);
  sortx(l, j);
end;

procedure sorty(l, r : longint);
var
  i, j, k : longint;
begin
  if l >= r then exit;
  i := l;
  j := r;
  k := p[l+random(r-l+1)].y;
  repeat
    while p[i].y < k do inc(i);
    while p[j].y > k do dec(j);
    if i <= j then
    begin
      swap1(i, j);
      inc(i); dec(j);
    end;
  until i > j;
  sorty(i, r);
  sorty(l, j);
end;

procedure init;
var
  i, j : longint;
begin
  sortx(1, n);
{  i := 1;
  while i < n do
  begin
    j := i;
    while p[j+1].x = p[i].x do inc(j);
    sorty(i, j);
    i := j+1;
  end;}
end;

function dis(i, j : longint) : extended;
begin
  dis := sqrt(sqr(p[i].x - p[j].x) + sqr(p[i].y - p[j].y));
end;

procedure init_dis;
var
  i, s, f, j : longint;
begin
  m := 0;
  for i := 1 to n do
  begin
    s := i;
    while (s > 1) and (p[s-1].x >= p[i].x-1000) do dec(s);
    f := i;
    while (f < n) and (p[f+1].x <= p[i].x+1000) do inc(f);
    for j := s to f do
      if (i <> j) and (dis(i, j) <= 1000) then
      begin
        inc(m);
        e[m, 1] := i;
        e[m, 2] := j;
      end;
  end;
end;

procedure creat_graph;
var
  i, u, v : longint;
begin
  fillchar(c, sizeof(c), 0);
  for i := 1 to m do
  begin
    u := e[i, 1];
    v := e[i, 2];
    inc(c[u]);
  end;
  for i := 2 to n+1 do inc(c[i], c[i-1]);
  for i := 1 to m do
  begin
    u := e[i, 1];
    v := e[i, 2];
    a[c[u]] := v;
    dec(c[u]);
  end;
end;

procedure sortup(c : integer);
var
  i, k : integer;
  w : longint;
begin
  k := h[c];
  w := d[h[c]];
  i := c;
  while i > 1 do
  begin
    if d[h[i shr 1]] < w then break;
    h[i] := h[i shr 1];
    v[h[i]] := i;
    i := i shr 1;
  end;
  h[i] := k;
  v[k] := i;
end;

procedure sortdown(c : integer);
var
  i, k : integer;
  w : longint;
begin
  k := h[c];
  w := d[h[c]];
  i := c shl 1;
  while i <= size do
  begin
    if (i < size) and (d[h[i+1]] < d[h[i]]) then inc(i);
    if d[h[i]] > w then break;
    h[i shr 1] := h[i];
    v[h[i]] := i shr 1;
    i := i shl 1;
  end;
  h[i shr 1] := k;
  v[k] := i shr 1;
end;

procedure initijk;
var
  i : longint;
begin
  size := 0;
  for i := 1 to n do
  begin
    if p[i].y <= 1000 then d[i] := 1
    else d[i] := oo;
    inc(size);
    v[i] := size;
    h[size] := i;
    sortup(size);
  end;
end;

procedure process;
var
  free : array[1..max] of boolean;
  i, j, u : longint;
begin
  init_dis;
  creat_graph;
  initijk;
  fillchar(free, sizeof(free), true);
  repeat
    i := h[1];
    h[1] := h[size];
    v[h[1]] := 1;
    dec(size);
    sortdown(1);
    if p[i].y >= l-1000 then
    begin
      res := d[i];
      exit;
    end;
    free[i] := false;
    for j := c[i]+1 to c[i+1] do
    begin
      u := a[j];
      if free[u] and (d[u] > d[i] + 1) then
      begin
        d[u] := d[i] + 1;
        sortup(v[u]);
      end;
    end;
  until size = 0;
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  inp;
  init;
  process;
  writeln(res);
  close(output);
  close(input);
end.
